package router

import (
	// "go/doc/comment"
	"my-go-project/controllers"
	"my-go-project/middlewares"

	"github.com/gin-gonic/gin"
)

/*
	除却登陆注册分组外，其余分组皆需使用JwtAuthMiddleware中间件
*/

func SetupRouter() *gin.Engine {
	r := gin.Default()

	r.Use(middlewares.CORSMiddleware())

	// 用户路由分组
	userGroup := r.Group("/users", middlewares.JwtAuthMiddleware())
	{
		userGroup.GET("/:id", controllers.GetUser)
		userGroup.POST("/modify", controllers.PostUser)
	}

	// 消息路由分组
	messageGroup := r.Group("/messages", middlewares.JwtAuthMiddleware())
	{
		messageGroup.GET("/like/:id", controllers.GetLikeMessage)
		messageGroup.GET("/comment/:id", controllers.GetCommentMessage)
		messageGroup.GET("/adoption/:id", controllers.GetAdoptionMessage)
	}

	// 点赞分组
	likeGroup := r.Group("/likes", middlewares.JwtAuthMiddleware())
	{
		likeGroup.POST("/passage/add", controllers.PostPassageLike)
		likeGroup.POST("/passage/undo", controllers.UndoPassageLike)
		likeGroup.POST("/comment/add", controllers.PostCommentLike)
		likeGroup.POST("/comment/undo", controllers.UndoCommentLike)
	}

	// 登录注册路由分组
	authGroup := r.Group("/auth")
	{
		authGroup.POST("/register", controllers.Register)
		authGroup.POST("/login", controllers.Login)
	}

	//领养分组
	// adoptGroup := r.Group("/adopt")
	adoptGroup := r.Group("/adopt", middlewares.JwtAuthMiddleware())
	{
		adoptGroup.POST("/application/add", controllers.PostAdoptApplication)
		adoptGroup.POST("/application/Evaluate", controllers.PostAdoptEvaluation)
		adoptGroup.POST("/application/updateprogress", controllers.UpdateAdoptProcess)
		adoptGroup.GET("/application/getapplication/:adoptID", controllers.GetAdoptApplications)
		adoptGroup.GET("/application/getadoptprogress/:adoptID", controllers.GetAdoptProcess)
		adoptGroup.GET("/application/getadoptevaluation/:adoptID/:userID", controllers.GetAdoptEvaluation)
		adoptGroup.GET("/application/getevaluationbyuser/:id", controllers.GetAdoptEvaluationByUser)
		adoptGroup.GET("/application/getUseradoptprocesslist/:id", controllers.GetUserAdoptProcess)
		adoptGroup.GET("/application/getApplicationStatus/:p_id/:u_id", controllers.GetAdoptStatus)
	}

	//获取文章列表分组
	// passageListGroup := r.Group("/passageList", middlewares.JwtAuthMiddleware())
	passageListGroup := r.Group("/passageList", middlewares.JwtAuthMiddleware())
	{
		passageListGroup.GET("/user/:id", controllers.GetUserPassage)
		passageListGroup.GET("/focus", controllers.GetFocusPassage)
		passageListGroup.GET("/square", controllers.GetSquarePassage)
		passageListGroup.GET("/adopt", controllers.GetAdoptPassage)
	}

	//文章搜索分组
	searchGroup := r.Group("/search", middlewares.JwtAuthMiddleware())
	{
		searchGroup.GET("/global/:SearchMessage", controllers.GlobalSearch)
		searchGroup.GET("/userPage/:SearchMessage/:UserID", controllers.UserSearch)
	}

	//管理文章分组
	passageManageGroup := r.Group("/passageMana", middlewares.JwtAuthMiddleware())
	// passageManageGroup := r.Group("/passageMana", middlewares.JwtAuthMiddleware())
	{
		passageManageGroup.POST("/upload", controllers.UploadPassage)
		passageManageGroup.POST("/delete", controllers.DeletePassage)
	}

	//获取文章内容分组
	passageGroup := r.Group("/passage", middlewares.JwtAuthMiddleware())
	{
		passageGroup.GET("/content/:id", controllers.GetPassage)
		passageGroup.GET("/pic/:id", controllers.GetPassagePic)
	}

	//管理关注信息分组
	focusGroup := r.Group("/focus", middlewares.JwtAuthMiddleware())
	{
		focusGroup.GET("/list", controllers.GetFollowList)
		focusGroup.POST("/add", controllers.AddFocus)
		focusGroup.POST("/delete", controllers.MoveFocus)
	}

	//管理评论信息分组
	// commentGroup := r.Group("/comment")
	commentGroup := r.Group("/comment", middlewares.JwtAuthMiddleware())
	{
		commentGroup.POST("/upload", controllers.UploadComment)
		commentGroup.POST("/delete", controllers.DeleteComment)
		commentGroup.GET("/list/:pa_id", controllers.GetCommentsByPassageID)

	}

	return r
}
